package com.huajin.codetest.util;

import java.io.File;

import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.qrcode.QrConfig;

/**
 * 二维码工具类
 *
 * @author hongwei.lian
 * @date 2020年10月20日 下午6:01:39
 */
public class QrCodeUtil {
	
	private QrCodeUtil() {}
	
	private static final int QRCODE_WIDTH = 420;
    
	private static final int QRCODE_HEIGHT = 420;
	
	/**
	 * 生成二维码文件
	 *
	 * @param url
	 * @param fllePath
	 * @return 
	 * @author hongwei.lian
	 * @date 2020年10月20日 下午6:04:36
	 */
	public static File generate(String url, String fllePath) {
		 return cn.hutool.extra.qrcode.QrCodeUtil.generate(url, QRCODE_WIDTH, QRCODE_HEIGHT, FileUtil.file(fllePath));
	}
	
	public static File generateWithLogo(String url, String fllePath, String logo) {
		QrConfig qrConfig = new QrConfig(QRCODE_WIDTH, QRCODE_HEIGHT)
				.setErrorCorrection(ErrorCorrectionLevel.H)
				.setImg(logo)
				.setMargin(1)
				.setRatio(6);
		return cn.hutool.extra.qrcode.QrCodeUtil.generate(url, qrConfig, FileUtil.file(fllePath));
	}
	
	public static void main(String[] args) {
		//-- https://idii-scm.chinawrr.com/searchResult?handle=88.280.151&qrcode=1
//		generateWithLogo("https://idii-scm.chinawrr.com/searchResult?handle=88.280.151&qrcode=1",
//				"C:\\Users\\Administrator\\Desktop\\内蒙古粮易达农业科技服务有限责任公司.png", 
//				"C:\\Users\\Administrator\\Desktop\\logo.jpg");
//		
//		//-- https://idii-scm.chinawrr.com/searchResult?handle=88.280.123&qrcode=1
//		generateWithLogo("https://idii-scm.chinawrr.com/searchResult?handle=88.280.123&qrcode=1",
//				"C:\\Users\\Administrator\\Desktop\\中国物资储运协会.png", 
//				"C:\\Users\\Administrator\\Desktop\\logo.png");
		
		//-- https://idii-scm.chinawrr.com/searchResult?handle=88.280.123/HY2021-0005
		//-- https://idii-scm.chinawrr.com/searchResult?handle=88.280.1&qrcode=1
		generateWithLogo("https://idii-scm.chinawrr.com/searchResult?handle=88.280.1&qrcode=1",
				"C:\\Users\\Administrator\\Desktop\\中仓登数据服务有限公司.png", 
				"C:\\Users\\Administrator\\Desktop\\中仓登半Logo.png");
		
//		//-- https://idii-scm.chinawrr.com/searchResult?handle=88.280.151/LYD-CK-0008
//		generateWithLogo("https://idii-scm.chinawrr.com/searchResult?handle=88.280.151/LYD-CK-0008",
//				"C:\\Users\\Administrator\\Desktop\\扎赉特旗小城子粮贸有限公司1号仓.png", 
//				"C:\\Users\\Administrator\\Desktop\\handlelogo.jpg");
	}

}
